using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OF.DB.DataAccess;
using OF.DB.Test.Entity;

namespace OF.DB.Test.DataAccess
{    
    public static partial class BlogDao
    {
        private const string AddSql = @"INSERT INTO dbo.[Blog](title, body, authoruid, documentType, pubDate, editDate) VALUES(@title, @body, @authoruid, @documentType, @pubDate, @editDate);
                SELECT id = SCOPE_IDENTITY();";
        private const string UpdateSql = @"UPDATE dbo.[Blog] SET title = @title, body = @body, authoruid = @authoruid, documentType = @documentType, editDate = @editDate WHERE id = @id;";
        private const string GetByIdSql = @"SELECT * FROM dbo.[Blog] WITH(NOLOCK) WHERE id = @id";
        private const string DeleteByIdSql = @"DELETE FROM dbo.[Blog] WHERE id = @id;";
        private const string GetALLListSql = @"SELECT * FROM dbo.[Blog] WITH(NOLOCK)";
		
        private static SqlParameter[] GetAddSqlParams(Blog entity)
        {
            return new SqlParameter[] {
                new SqlParameter("@title", SqlDbType.VarChar) { Value = DBHelper.GetParamValue(entity.title) },
               new SqlParameter("@body", SqlDbType.VarChar) { Value = DBHelper.GetParamValue(entity.body) },
               new SqlParameter("@authoruid", SqlDbType.Int) { Value = DBHelper.GetParamValue(entity.authoruid) },
               new SqlParameter("@documentType", SqlDbType.TinyInt) { Value = DBHelper.GetParamValue(entity.documentType) },
               new SqlParameter("@pubDate", SqlDbType.DateTime) { Value = DBHelper.GetParamValue(entity.pubDate) },
               new SqlParameter("@editDate", SqlDbType.DateTime) { Value = DBHelper.GetParamValue(entity.editDate) }
            };
        }

        private static SqlParameter[] GetUpdateSqlParams(Blog entity)
        {
            return new SqlParameter[] {
                new SqlParameter("@id", SqlDbType.Int) { Value = DBHelper.GetParamValue(entity.id) },
               new SqlParameter("@title", SqlDbType.VarChar) { Value = DBHelper.GetParamValue(entity.title) },
               new SqlParameter("@body", SqlDbType.VarChar) { Value = DBHelper.GetParamValue(entity.body) },
               new SqlParameter("@authoruid", SqlDbType.Int) { Value = DBHelper.GetParamValue(entity.authoruid) },
               new SqlParameter("@documentType", SqlDbType.TinyInt) { Value = DBHelper.GetParamValue(entity.documentType) },
               new SqlParameter("@editDate", SqlDbType.DateTime) { Value = DBHelper.GetParamValue(entity.editDate) }
            };
        }

        private static SqlParameter[] GetGetByIdSqlParams(Blog entity)
        {
            return new SqlParameter[] {
                new SqlParameter("@id", SqlDbType.Int) { Value = DBHelper.GetParamValue(entity.id) }
            };
        }

        private static SqlParameter[] GetDeleteByIdSqlParams(Blog entity)
        {
            return new SqlParameter[] {
                new SqlParameter("@id", SqlDbType.Int) { Value = DBHelper.GetParamValue(entity.id) }
            };
        }
    }
}